﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Studio7i.CapaNegocio;
using Studio7i.CapaDominio;

namespace Studio7i.Controllers
{
    public class ArmadoSalaController : Controller
    {
        // Dependencias
        #region Dependencias a inyectarse con Spring.NET
        IAdministradorService AdministradorService = null;
        #endregion
        
        //
        // GET: /ArmadoSala/
        public ActionResult Index()
        {
            ICollection<ArmadoDeSala> modelo = AdministradorService.ListarArmadoSala();
            TempData["Servicios"] = Listarservicios();
            TempData["Instrumentos"] = ListarInstrumentos();
            TempData["Salas"] = ListarSalas();
            return View(modelo);
        }

        private object ListarSalas()
        {
            throw new NotImplementedException();
        }

        private ICollection<SelectListItem> Listarservicios()
        {
            ICollection<SelectListItem> Servicios = new List<SelectListItem>();
            Servicios.Add(new SelectListItem() { Value = string.Empty, Text = "Seleccione.." });
            foreach (Servicio Servicio in AdministradorService.listarservicios())
                Servicios.Add(new SelectListItem()
                {
                    Value = Servicio.codigo.ToString(),
                    Text = Servicio.descripcion
                });
            return Servicios;
        }

        private ICollection<SelectListItem> ListarInstrumentos()
        {
            ICollection<SelectListItem> Instrumentos = new List<SelectListItem>();
            Instrumentos.Add(new SelectListItem() { Value = string.Empty, Text = "Seleccione.." });
            foreach (Instrumento Instrumento in AdministradorService.listarinstrumentos())
                Instrumentos.Add(new SelectListItem()
                {
                    Value = Instrumento.codigo.ToString(),
                    Text = Instrumento.caracteristicas
                });
            return Instrumentos;
        }

        private ICollection<SelectListItem> Listarsalas()
        {
            ICollection<SelectListItem> Salas = new List<SelectListItem>();
            Salas.Add(new SelectListItem() { Value = string.Empty, Text = "Seleccione.." });
            foreach (Sala sala in AdministradorService.ListarSalas())
                Salas.Add(new SelectListItem()
                {
                    Value = sala.CoSala.ToString(),
                    Text = sala.TxCaracteristicas
                });
            return Salas;
        }




        //
        // GET: /ArmadoSala/Details/5

        public ActionResult Details(int codigo)
        {
            ArmadoDeSala modelo = AdministradorService.ObtenerArmadoSala(codigo);
            return View(modelo);
        }

        //
        // GET: /ArmadoSala/Create

        public ActionResult Create()
        {


            return View();
        } 

        //
        // POST: /ArmadoSala/Create

        [HttpPost]
        public ActionResult Create(FormCollection formulario)
        {
            try
            {
                int Codigo = int.Parse(formulario["CoArmado"]);
                int SsArmado = int.Parse(formulario["SsArmado"]);
                int CoSala = int.Parse(formulario["CoSala"]);
                int CoInstrumento = int.Parse(formulario["CoInstrumento"]);
                int CoServicios = int.Parse(formulario["CoServicios"]);
                ArmadoDeSala ArmadoDeSalaRegistrado = AdministradorService.RegistrarArmadoSala(Codigo, SsArmado, CoSala, CoInstrumento, CoServicios);
                TempData["mensaje"] = "Armado de sala " + ArmadoDeSalaRegistrado.CoArmado + " Registrado satisfactoriamente";
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return View("Create");
            }
        }
        
        //
        // GET: /ArmadoSala/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /ArmadoSala/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /ArmadoSala/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /ArmadoSala/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
